package com.mcc.app.stock.service.impl;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mcc.app.stock.domain.SinterMatter;
import com.mcc.app.stock.mapper.SinterMatterMapper;
import com.mcc.app.stock.service.ISinterMatterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 物料配置Service业务层处理
 *
 * @author gxy
 * @date 2024-07-30
 */
@Service
public class SinterMatterServiceImpl implements ISinterMatterService {

    @Autowired
    private SinterMatterMapper sinterMatterMapper;

    /**
     * 查询物料配置
     *
     * @param id 物料配置ID
     * @return 物料配置
     */
    @Override
    public SinterMatter selectSinterMatterById(Long id) {
        return sinterMatterMapper.selectById(id);
    }

    /**
     * 查询物料配置列表
     *
     * @param sinterMatter 物料配置
     * @return 物料配置
     */
    @Override
    public List<SinterMatter> selectSinterMatterList(SinterMatter sinterMatter) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (ObjectUtil.isNotEmpty(sinterMatter)) {
            queryWrapper.like(ObjectUtil.isNotEmpty(sinterMatter.getMatterName()), "matter_name", sinterMatter.getMatterName());
            queryWrapper.eq(ObjectUtil.isNotEmpty(sinterMatter.getMatterType()), "matter_type", sinterMatter.getMatterType());
        }
        return sinterMatterMapper.selectList(queryWrapper);
    }

    /**
     * 新增物料配置
     *
     * @param sinterMatter 物料配置
     * @return 结果
     */
    @Override
    public int insertSinterMatter(SinterMatter sinterMatter) {
        return sinterMatterMapper.insert(sinterMatter);
    }

    /**
     * 修改物料配置
     *
     * @param sinterMatter 物料配置
     * @return 结果
     */
    @Override
    public int updateSinterMatter(SinterMatter sinterMatter) {
        return sinterMatterMapper.updateById(sinterMatter);
    }

    /**
     * 删除物料配置
     *
     * @param id 物料配置ID
     * @return 结果
     */
    @Override
    public int deleteSinterMatterById(Long id) {
        return sinterMatterMapper.deleteById(id);
    }

    /**
     * 批量删除物料配置
     *
     * @param ids 物料配置ID
     * @return 结果
     */
    @Override
    public int deleteSinterMatterByIds(Long[] ids) {
        if (ids.length == 0) return 0;
        return sinterMatterMapper.deleteBatchIds(ListUtil.toList(ids));
    }
}
